import utils from '@utils/utils'
import api from '../apis/instance'

export default class Song {
    constructor ({
        id,
        name,
        mvId,
        singer,
        album,
        alia,
        duration,
        url,
        vip,
        license,
        publishTime
    }) {
        this.id = id
        this.name = name
        this.mvId = mvId
        this.singer = singer
        this.album = album
        this.alia = alia
        this.duration = duration
        this.url = url
        this.vip = vip
        this.license = license
        this.publishTime = publishTime
    }
}

export function formatSongInfo (params) {
    return new Song({
        id: String(params.id),
        name: params.name,
        mvId: params.mv,
        singer: params.ar,
        album: params.al,
        alia: params.alia,
        vip: params.fee === 1,
        license: params.license && false,
        duration: utils.formatSongTime(params.dt),
        url: `${api.rootUrl}/api/music/getMusic?id=${params.id}`,
        publishTime: utils.formatMsgTime(params.publishTime)
    })
}

export function formatLocSongInfo (params) {
    // window.console.log('[信息]转换本地音乐', params)
    return new Song({
        id: String(params.id),
        name: params.title,
        mvId: params.wyyId,
        singer: [{
            id: params.artistId,
            name: params.artist
        }],
        album: {
            id: params.albumId,
            name: params.album
        },
        alia: params.alia,
        vip: false,
        license: false,
        duration: params.songLength ? utils.formatSongTime(Number(params.songLength) * 1000) : '',
        url: `${api.rootUrl}/api/music/getMusic?id=${params.id}`,
        publishTime: ''
    })
}
